
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/19/2010 11:57:25
-- Generated from EDMX file: C:\Users\stewarts\Documents\Visual Studio 2010\Projects\APH.Parliament2.0.Data\APH.Parl2.Shared.Data\Parl2\Parl2.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Parliament2.0];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BillParliament]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bills] DROP CONSTRAINT [FK_BillParliament];
GO
IF OBJECT_ID(N'[dbo].[FK_BillScheduleOfAmendments]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScheduleOfAmendments] DROP CONSTRAINT [FK_BillScheduleOfAmendments];
GO
IF OBJECT_ID(N'[dbo].[FK_BillProposedAmendment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProposedAmendments] DROP CONSTRAINT [FK_BillProposedAmendment];
GO
IF OBJECT_ID(N'[dbo].[FK_BillExplanatoryMemorandum]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExplanatoryMemorandums] DROP CONSTRAINT [FK_BillExplanatoryMemorandum];
GO
IF OBJECT_ID(N'[dbo].[FK_BillStage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Stages] DROP CONSTRAINT [FK_BillStage];
GO
IF OBJECT_ID(N'[dbo].[FK_BillChamber]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bills] DROP CONSTRAINT [FK_BillChamber];
GO
IF OBJECT_ID(N'[dbo].[FK_BillsDigestBill]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillsDigests] DROP CONSTRAINT [FK_BillsDigestBill];
GO
IF OBJECT_ID(N'[dbo].[FK_ParliamentSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sessions] DROP CONSTRAINT [FK_ParliamentSession];
GO
IF OBJECT_ID(N'[dbo].[FK_ParliamentarianChamber]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Parliamentarians] DROP CONSTRAINT [FK_ParliamentarianChamber];
GO
IF OBJECT_ID(N'[dbo].[FK_ParliamentarianParty]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Parliamentarians] DROP CONSTRAINT [FK_ParliamentarianParty];
GO
IF OBJECT_ID(N'[dbo].[FK_ParliamentarianPortfolio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Portfolios] DROP CONSTRAINT [FK_ParliamentarianPortfolio];
GO
IF OBJECT_ID(N'[dbo].[FK_BillSponsor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bills] DROP CONSTRAINT [FK_BillSponsor];
GO
IF OBJECT_ID(N'[dbo].[FK_BillPortfolio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bills] DROP CONSTRAINT [FK_BillPortfolio];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Bills]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Bills];
GO
IF OBJECT_ID(N'[dbo].[Parliaments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Parliaments];
GO
IF OBJECT_ID(N'[dbo].[Stages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Stages];
GO
IF OBJECT_ID(N'[dbo].[ScheduleOfAmendments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ScheduleOfAmendments];
GO
IF OBJECT_ID(N'[dbo].[ProposedAmendments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProposedAmendments];
GO
IF OBJECT_ID(N'[dbo].[ExplanatoryMemorandums]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExplanatoryMemorandums];
GO
IF OBJECT_ID(N'[dbo].[Parliamentarians]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Parliamentarians];
GO
IF OBJECT_ID(N'[dbo].[Portfolios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Portfolios];
GO
IF OBJECT_ID(N'[dbo].[Chambers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Chambers];
GO
IF OBJECT_ID(N'[dbo].[BillsDigests]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BillsDigests];
GO
IF OBJECT_ID(N'[dbo].[Sessions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sessions];
GO
IF OBJECT_ID(N'[dbo].[Parties]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Parties];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Bills'
CREATE TABLE [dbo].[Bills] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [Summary] nvarchar(max)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Digest] nvarchar(max)  NOT NULL,
    [ChamberId] int  NOT NULL,
    [Number] nvarchar(max)  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [LongTitle] nvarchar(max)  NOT NULL,
    [TariffPropType] nvarchar(max)  NULL,
    [BillHomePILink] nvarchar(max)  NOT NULL,
    [LatestStage] nvarchar(max)  NULL,
    [BillTextPILink] nvarchar(max)  NOT NULL,
    [Parliament_Id] int  NOT NULL,
    [Parliamentarian_Id] int  NULL,
    [Portfolio_Id] int  NULL
);
GO

-- Creating table 'Parliaments'
CREATE TABLE [dbo].[Parliaments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Number] int  NOT NULL,
    [DateFrom] datetime  NOT NULL,
    [DateTo] datetime  NULL
);
GO

-- Creating table 'Stages'
CREATE TABLE [dbo].[Stages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Progress] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [BillId] int  NOT NULL
);
GO

-- Creating table 'ScheduleOfAmendments'
CREATE TABLE [dbo].[ScheduleOfAmendments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [BillId] int  NOT NULL
);
GO

-- Creating table 'ProposedAmendments'
CREATE TABLE [dbo].[ProposedAmendments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [BillId] int  NOT NULL
);
GO

-- Creating table 'ExplanatoryMemorandums'
CREATE TABLE [dbo].[ExplanatoryMemorandums] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PILink] nvarchar(max)  NOT NULL,
    [BillId] int  NOT NULL,
    [SequenceNumber] int  NOT NULL
);
GO

-- Creating table 'Parliamentarians'
CREATE TABLE [dbo].[Parliamentarians] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Surname] nvarchar(max)  NOT NULL,
    [GivenName] nvarchar(max)  NOT NULL,
    [Image] varbinary(max)  NOT NULL,
    [Salutation] nvarchar(max)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [DateElected] datetime  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [WebsiteAddress] nvarchar(max)  NOT NULL,
    [FacebookAddress] nvarchar(max)  NOT NULL,
    [TwitterAddress] nvarchar(max)  NOT NULL,
    [ParliamentPhone] nvarchar(max)  NOT NULL,
    [ParliamentFax] nvarchar(max)  NOT NULL,
    [ParliamentEmail] nvarchar(max)  NOT NULL,
    [ElectoralOfficeUnit] nvarchar(max)  NOT NULL,
    [ElectoralOfficeNumber] nvarchar(max)  NOT NULL,
    [ElectoralOfficeStreet] nvarchar(max)  NOT NULL,
    [ElectoralOfficeSuburb] nvarchar(max)  NOT NULL,
    [ElectoralOfficeState] nvarchar(max)  NOT NULL,
    [ElectoralOfficePostcode] nvarchar(max)  NOT NULL,
    [ElectoralOfficePhone] nvarchar(max)  NOT NULL,
    [ElectoralOfficeFax] nvarchar(max)  NOT NULL,
    [FirstSpeech] nvarchar(max)  NOT NULL,
    [Chamber_Id] int  NOT NULL,
    [Party_Id] int  NULL
);
GO

-- Creating table 'Portfolios'
CREATE TABLE [dbo].[Portfolios] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [DateFrom] datetime  NOT NULL,
    [DateTo] datetime  NULL,
    [Parliamentarian_Id] int  NOT NULL
);
GO

-- Creating table 'Chambers'
CREATE TABLE [dbo].[Chambers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BillsDigests'
CREATE TABLE [dbo].[BillsDigests] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Link] nvarchar(max)  NOT NULL,
    [Bill_Id] int  NOT NULL
);
GO

-- Creating table 'Sessions'
CREATE TABLE [dbo].[Sessions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ParliamentId] int  NOT NULL,
    [DateFrom] datetime  NOT NULL,
    [DateTo] datetime  NULL
);
GO

-- Creating table 'Parties'
CREATE TABLE [dbo].[Parties] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Website] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SittingPeriods'
CREATE TABLE [dbo].[SittingPeriods] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SessionId] int  NOT NULL
);
GO

-- Creating table 'Sittings'
CREATE TABLE [dbo].[Sittings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SittingPeriodId] int  NOT NULL,
    [ChamberId] int  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [Property] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Committees'
CREATE TABLE [dbo].[Committees] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ParliamentId] int  NOT NULL
);
GO

-- Creating table 'Inquiries'
CREATE TABLE [dbo].[Inquiries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CommitteeId] int  NOT NULL
);
GO

-- Creating table 'Hearings'
CREATE TABLE [dbo].[Hearings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [InquiryId] int  NOT NULL
);
GO

-- Creating table 'HansardYears'
CREATE TABLE [dbo].[HansardYears] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'Sections'
CREATE TABLE [dbo].[Sections] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [HansardId] int  NOT NULL,
    [CommitteeHansardId] int  NOT NULL,
    [ChamberHansardId] int  NOT NULL
);
GO

-- Creating table 'Segments'
CREATE TABLE [dbo].[Segments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SectionId] int  NOT NULL
);
GO

-- Creating table 'ChamberHansards'
CREATE TABLE [dbo].[ChamberHansards] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [HansardYearId] int  NOT NULL,
    [SittingId] int  NOT NULL
);
GO

-- Creating table 'CommitteeHansards'
CREATE TABLE [dbo].[CommitteeHansards] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [HansardYearId] int  NOT NULL,
    [HearingId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Bills'
ALTER TABLE [dbo].[Bills]
ADD CONSTRAINT [PK_Bills]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Parliaments'
ALTER TABLE [dbo].[Parliaments]
ADD CONSTRAINT [PK_Parliaments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Stages'
ALTER TABLE [dbo].[Stages]
ADD CONSTRAINT [PK_Stages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ScheduleOfAmendments'
ALTER TABLE [dbo].[ScheduleOfAmendments]
ADD CONSTRAINT [PK_ScheduleOfAmendments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProposedAmendments'
ALTER TABLE [dbo].[ProposedAmendments]
ADD CONSTRAINT [PK_ProposedAmendments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExplanatoryMemorandums'
ALTER TABLE [dbo].[ExplanatoryMemorandums]
ADD CONSTRAINT [PK_ExplanatoryMemorandums]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Parliamentarians'
ALTER TABLE [dbo].[Parliamentarians]
ADD CONSTRAINT [PK_Parliamentarians]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Portfolios'
ALTER TABLE [dbo].[Portfolios]
ADD CONSTRAINT [PK_Portfolios]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Chambers'
ALTER TABLE [dbo].[Chambers]
ADD CONSTRAINT [PK_Chambers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BillsDigests'
ALTER TABLE [dbo].[BillsDigests]
ADD CONSTRAINT [PK_BillsDigests]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sessions'
ALTER TABLE [dbo].[Sessions]
ADD CONSTRAINT [PK_Sessions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Parties'
ALTER TABLE [dbo].[Parties]
ADD CONSTRAINT [PK_Parties]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SittingPeriods'
ALTER TABLE [dbo].[SittingPeriods]
ADD CONSTRAINT [PK_SittingPeriods]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sittings'
ALTER TABLE [dbo].[Sittings]
ADD CONSTRAINT [PK_Sittings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Committees'
ALTER TABLE [dbo].[Committees]
ADD CONSTRAINT [PK_Committees]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Inquiries'
ALTER TABLE [dbo].[Inquiries]
ADD CONSTRAINT [PK_Inquiries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Hearings'
ALTER TABLE [dbo].[Hearings]
ADD CONSTRAINT [PK_Hearings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'HansardYears'
ALTER TABLE [dbo].[HansardYears]
ADD CONSTRAINT [PK_HansardYears]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sections'
ALTER TABLE [dbo].[Sections]
ADD CONSTRAINT [PK_Sections]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Segments'
ALTER TABLE [dbo].[Segments]
ADD CONSTRAINT [PK_Segments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ChamberHansards'
ALTER TABLE [dbo].[ChamberHansards]
ADD CONSTRAINT [PK_ChamberHansards]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CommitteeHansards'
ALTER TABLE [dbo].[CommitteeHansards]
ADD CONSTRAINT [PK_CommitteeHansards]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Parliament_Id] in table 'Bills'
ALTER TABLE [dbo].[Bills]
ADD CONSTRAINT [FK_BillParliament]
    FOREIGN KEY ([Parliament_Id])
    REFERENCES [dbo].[Parliaments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillParliament'
CREATE INDEX [IX_FK_BillParliament]
ON [dbo].[Bills]
    ([Parliament_Id]);
GO

-- Creating foreign key on [BillId] in table 'ScheduleOfAmendments'
ALTER TABLE [dbo].[ScheduleOfAmendments]
ADD CONSTRAINT [FK_BillScheduleOfAmendments]
    FOREIGN KEY ([BillId])
    REFERENCES [dbo].[Bills]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillScheduleOfAmendments'
CREATE INDEX [IX_FK_BillScheduleOfAmendments]
ON [dbo].[ScheduleOfAmendments]
    ([BillId]);
GO

-- Creating foreign key on [BillId] in table 'ProposedAmendments'
ALTER TABLE [dbo].[ProposedAmendments]
ADD CONSTRAINT [FK_BillProposedAmendment]
    FOREIGN KEY ([BillId])
    REFERENCES [dbo].[Bills]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillProposedAmendment'
CREATE INDEX [IX_FK_BillProposedAmendment]
ON [dbo].[ProposedAmendments]
    ([BillId]);
GO

-- Creating foreign key on [BillId] in table 'ExplanatoryMemorandums'
ALTER TABLE [dbo].[ExplanatoryMemorandums]
ADD CONSTRAINT [FK_BillExplanatoryMemorandum]
    FOREIGN KEY ([BillId])
    REFERENCES [dbo].[Bills]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillExplanatoryMemorandum'
CREATE INDEX [IX_FK_BillExplanatoryMemorandum]
ON [dbo].[ExplanatoryMemorandums]
    ([BillId]);
GO

-- Creating foreign key on [BillId] in table 'Stages'
ALTER TABLE [dbo].[Stages]
ADD CONSTRAINT [FK_BillStage]
    FOREIGN KEY ([BillId])
    REFERENCES [dbo].[Bills]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillStage'
CREATE INDEX [IX_FK_BillStage]
ON [dbo].[Stages]
    ([BillId]);
GO

-- Creating foreign key on [ChamberId] in table 'Bills'
ALTER TABLE [dbo].[Bills]
ADD CONSTRAINT [FK_BillChamber]
    FOREIGN KEY ([ChamberId])
    REFERENCES [dbo].[Chambers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillChamber'
CREATE INDEX [IX_FK_BillChamber]
ON [dbo].[Bills]
    ([ChamberId]);
GO

-- Creating foreign key on [Bill_Id] in table 'BillsDigests'
ALTER TABLE [dbo].[BillsDigests]
ADD CONSTRAINT [FK_BillsDigestBill]
    FOREIGN KEY ([Bill_Id])
    REFERENCES [dbo].[Bills]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillsDigestBill'
CREATE INDEX [IX_FK_BillsDigestBill]
ON [dbo].[BillsDigests]
    ([Bill_Id]);
GO

-- Creating foreign key on [ParliamentId] in table 'Sessions'
ALTER TABLE [dbo].[Sessions]
ADD CONSTRAINT [FK_ParliamentSession]
    FOREIGN KEY ([ParliamentId])
    REFERENCES [dbo].[Parliaments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParliamentSession'
CREATE INDEX [IX_FK_ParliamentSession]
ON [dbo].[Sessions]
    ([ParliamentId]);
GO

-- Creating foreign key on [Chamber_Id] in table 'Parliamentarians'
ALTER TABLE [dbo].[Parliamentarians]
ADD CONSTRAINT [FK_ParliamentarianChamber]
    FOREIGN KEY ([Chamber_Id])
    REFERENCES [dbo].[Chambers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParliamentarianChamber'
CREATE INDEX [IX_FK_ParliamentarianChamber]
ON [dbo].[Parliamentarians]
    ([Chamber_Id]);
GO

-- Creating foreign key on [Party_Id] in table 'Parliamentarians'
ALTER TABLE [dbo].[Parliamentarians]
ADD CONSTRAINT [FK_ParliamentarianParty]
    FOREIGN KEY ([Party_Id])
    REFERENCES [dbo].[Parties]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParliamentarianParty'
CREATE INDEX [IX_FK_ParliamentarianParty]
ON [dbo].[Parliamentarians]
    ([Party_Id]);
GO

-- Creating foreign key on [Parliamentarian_Id] in table 'Portfolios'
ALTER TABLE [dbo].[Portfolios]
ADD CONSTRAINT [FK_ParliamentarianPortfolio]
    FOREIGN KEY ([Parliamentarian_Id])
    REFERENCES [dbo].[Parliamentarians]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParliamentarianPortfolio'
CREATE INDEX [IX_FK_ParliamentarianPortfolio]
ON [dbo].[Portfolios]
    ([Parliamentarian_Id]);
GO

-- Creating foreign key on [Parliamentarian_Id] in table 'Bills'
ALTER TABLE [dbo].[Bills]
ADD CONSTRAINT [FK_BillSponsor]
    FOREIGN KEY ([Parliamentarian_Id])
    REFERENCES [dbo].[Parliamentarians]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillSponsor'
CREATE INDEX [IX_FK_BillSponsor]
ON [dbo].[Bills]
    ([Parliamentarian_Id]);
GO

-- Creating foreign key on [Portfolio_Id] in table 'Bills'
ALTER TABLE [dbo].[Bills]
ADD CONSTRAINT [FK_BillPortfolio]
    FOREIGN KEY ([Portfolio_Id])
    REFERENCES [dbo].[Portfolios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillPortfolio'
CREATE INDEX [IX_FK_BillPortfolio]
ON [dbo].[Bills]
    ([Portfolio_Id]);
GO

-- Creating foreign key on [SessionId] in table 'SittingPeriods'
ALTER TABLE [dbo].[SittingPeriods]
ADD CONSTRAINT [FK_SessionSittingPeriod]
    FOREIGN KEY ([SessionId])
    REFERENCES [dbo].[Sessions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SessionSittingPeriod'
CREATE INDEX [IX_FK_SessionSittingPeriod]
ON [dbo].[SittingPeriods]
    ([SessionId]);
GO

-- Creating foreign key on [SittingPeriodId] in table 'Sittings'
ALTER TABLE [dbo].[Sittings]
ADD CONSTRAINT [FK_SittingPeriodSitting]
    FOREIGN KEY ([SittingPeriodId])
    REFERENCES [dbo].[SittingPeriods]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SittingPeriodSitting'
CREATE INDEX [IX_FK_SittingPeriodSitting]
ON [dbo].[Sittings]
    ([SittingPeriodId]);
GO

-- Creating foreign key on [ParliamentId] in table 'Committees'
ALTER TABLE [dbo].[Committees]
ADD CONSTRAINT [FK_ParliamentCommittee]
    FOREIGN KEY ([ParliamentId])
    REFERENCES [dbo].[Parliaments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParliamentCommittee'
CREATE INDEX [IX_FK_ParliamentCommittee]
ON [dbo].[Committees]
    ([ParliamentId]);
GO

-- Creating foreign key on [CommitteeId] in table 'Inquiries'
ALTER TABLE [dbo].[Inquiries]
ADD CONSTRAINT [FK_CommitteeInquiry]
    FOREIGN KEY ([CommitteeId])
    REFERENCES [dbo].[Committees]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CommitteeInquiry'
CREATE INDEX [IX_FK_CommitteeInquiry]
ON [dbo].[Inquiries]
    ([CommitteeId]);
GO

-- Creating foreign key on [InquiryId] in table 'Hearings'
ALTER TABLE [dbo].[Hearings]
ADD CONSTRAINT [FK_InquiryHearing]
    FOREIGN KEY ([InquiryId])
    REFERENCES [dbo].[Inquiries]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_InquiryHearing'
CREATE INDEX [IX_FK_InquiryHearing]
ON [dbo].[Hearings]
    ([InquiryId]);
GO

-- Creating foreign key on [SectionId] in table 'Segments'
ALTER TABLE [dbo].[Segments]
ADD CONSTRAINT [FK_SectionSegment]
    FOREIGN KEY ([SectionId])
    REFERENCES [dbo].[Sections]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectionSegment'
CREATE INDEX [IX_FK_SectionSegment]
ON [dbo].[Segments]
    ([SectionId]);
GO

-- Creating foreign key on [ChamberId] in table 'Sittings'
ALTER TABLE [dbo].[Sittings]
ADD CONSTRAINT [FK_ChamberSitting]
    FOREIGN KEY ([ChamberId])
    REFERENCES [dbo].[Chambers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ChamberSitting'
CREATE INDEX [IX_FK_ChamberSitting]
ON [dbo].[Sittings]
    ([ChamberId]);
GO

-- Creating foreign key on [HansardYearId] in table 'ChamberHansards'
ALTER TABLE [dbo].[ChamberHansards]
ADD CONSTRAINT [FK_HansardYearChamberHansard]
    FOREIGN KEY ([HansardYearId])
    REFERENCES [dbo].[HansardYears]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HansardYearChamberHansard'
CREATE INDEX [IX_FK_HansardYearChamberHansard]
ON [dbo].[ChamberHansards]
    ([HansardYearId]);
GO

-- Creating foreign key on [SittingId] in table 'ChamberHansards'
ALTER TABLE [dbo].[ChamberHansards]
ADD CONSTRAINT [FK_SittingChamberHansard]
    FOREIGN KEY ([SittingId])
    REFERENCES [dbo].[Sittings]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SittingChamberHansard'
CREATE INDEX [IX_FK_SittingChamberHansard]
ON [dbo].[ChamberHansards]
    ([SittingId]);
GO

-- Creating foreign key on [HansardYearId] in table 'CommitteeHansards'
ALTER TABLE [dbo].[CommitteeHansards]
ADD CONSTRAINT [FK_HansardYearCommitteeHansard]
    FOREIGN KEY ([HansardYearId])
    REFERENCES [dbo].[HansardYears]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HansardYearCommitteeHansard'
CREATE INDEX [IX_FK_HansardYearCommitteeHansard]
ON [dbo].[CommitteeHansards]
    ([HansardYearId]);
GO

-- Creating foreign key on [HearingId] in table 'CommitteeHansards'
ALTER TABLE [dbo].[CommitteeHansards]
ADD CONSTRAINT [FK_HearingCommitteeHansard]
    FOREIGN KEY ([HearingId])
    REFERENCES [dbo].[Hearings]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HearingCommitteeHansard'
CREATE INDEX [IX_FK_HearingCommitteeHansard]
ON [dbo].[CommitteeHansards]
    ([HearingId]);
GO

-- Creating foreign key on [CommitteeHansardId] in table 'Sections'
ALTER TABLE [dbo].[Sections]
ADD CONSTRAINT [FK_CommitteeHansardSection]
    FOREIGN KEY ([CommitteeHansardId])
    REFERENCES [dbo].[CommitteeHansards]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CommitteeHansardSection'
CREATE INDEX [IX_FK_CommitteeHansardSection]
ON [dbo].[Sections]
    ([CommitteeHansardId]);
GO

-- Creating foreign key on [ChamberHansardId] in table 'Sections'
ALTER TABLE [dbo].[Sections]
ADD CONSTRAINT [FK_ChamberHansardSection]
    FOREIGN KEY ([ChamberHansardId])
    REFERENCES [dbo].[ChamberHansards]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ChamberHansardSection'
CREATE INDEX [IX_FK_ChamberHansardSection]
ON [dbo].[Sections]
    ([ChamberHansardId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------